x = torch.ones(2, 3)*0.2
net1 = nn.Linear(3, 3)
net2 = nn.Linear(3, 3)
loss_fun = torch.nn.MSELoss()
tgt1 = torch.ones(2, 3)*0.5
pred1 = net1(x)
loss1=loss_fun(pred1, tgt1)
tgt2 = torch.ones(2, 3)
pred2 = net2(x)
loss2 = loss_fun(pred2, tgt2)
tol_loss= loss2+loss1
# &&&&&&
tol_loss.backward() # 梯度之和等于和的梯度
# loss1.backward()  # 分别求梯度
# loss2.backward()
# ++++++  
